home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Function Offsets
- Date: Mon, 18 Mar 96 12:11:49 GMT
- Organization: none
- Message-ID: <827151109snz@genesis.demon.co.uk>
- References: <4ih3p4$4gn@cloner4.netcom.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4ih3p4$4gn@cloner4.netcom.com>
- fame1@ix.netcom.com "Matt Kittleson" writes:
-
- >Is this the best way to get the offset of a function?
-
- The 'value' of the identifier main gives you a pointer to the main function.
- However functions aren't objects and you can't perform pointer arithmetic
- on function pointers.
-
- >void main()
-
- main returns int in C.
-
- >{
- >void funct1()
- >
- >some code here...blah...blah...blah
- >
- >}
- >
- >Would i then be able to printf the address out?
-
- printf doesn't provide a portable way of printing function pointers.
-
- >Then if I loaded the
- >program by just malloc'n the memory, jump to the function by
- >subtracting offsets? I have been meaning to try it, but have had
- >little time.
-
- This may work on a few systems (e.g. by casting the pointer returned by
- malloc to an appropriate function pointer and calling through that) but
- such operations are illegal in C (they result in undefined behaviour).
- On many systems code has to go in a code segment so memory allocated by
- malloc would be totally inappropriate.
-
- >Any other info on either this or dynamic linking in general would be
- >greatly appreaciated.
-
- If your system supports dynamic linking it will provide some sort of
- interface to call up those facilities. However this is highly system
- dependent so you should refer to your system's documentation or failing
- that a newsgroup related to your particular system.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-